package com.ex.web;

import com.ex.cache.ShiroRetryCache;
import com.ex.common.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author longdeng
 * @Date 2019/10/8 0:30
 */
@Api(value = "缓存API", description = "缓存API", tags = {"缓存API"})
@RestController
@RequestMapping("/api/cache")
public class CacheController {

    @Autowired
    private ShiroRetryCache shiroRetryCache;

    @ApiOperation("获取值到缓存中")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "键"),
            @ApiImplicitParam(name = "value", value = "值"),
    })
    @RequestMapping(value = "/cache", method =RequestMethod.GET)
    public ResultData put(String key, Integer value) {
        Integer integer = shiroRetryCache.getRetryNumber(key, value);
        return ResultData.success(integer);
    }

    @ApiOperation("从缓存中移除值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "键"),
    })
    @RequestMapping(value = "/evict", method = RequestMethod.GET)
    public ResultData evit(String key) {
        shiroRetryCache.evictRetryNumber(key);
        return ResultData.success("");
    }

}
